from project import *
from Tkinter import *
from Tkinter import *
from tkSimpleDialog import *
import time
import datetime

class ScrumsFrame(Frame):
    """
    Represents the frame that provides a user interface to access project information.
    """
    
    def __init__(self, parentControl, listener):
        Frame.__init__(self, parentControl)
        self.listener = listener
        
        label = Label(self, text = "Dates")
        label.grid(row = 0, column = 0)
        
        self.datesListbox = Listbox(self)
        self.datesListbox.bind("<Button-1>", self._showSelectedScrum)
        self.datesListbox.grid(row = 1, column = 0, rowspan = 6, sticky=N+S)
        
        label = Label(self, text = "Membres")
        label.grid(row = 0, column = 1)
        
        self.membersListbox = Listbox(self)
        self.membersListbox.bind("<Button-1>", self._showSelectedScrum)
        self.membersListbox.grid(row = 1, column = 1, rowspan = 6, sticky=N+S)
        
        label = Label(self, text = "Accompli")
        label.grid(row = 1, column = 2)
        
        self.accomplishedTextbox = Text(self, width=30, height=10)
        self.accomplishedTextbox.config(state = DISABLED)
        self.accomplishedTextbox.grid(row = 2, column = 2)
        
        label = Label(self, text = "Problemes")
        label.grid(row = 3, column = 2)
        
        self.problemsTextbox = Text(self, width=30, height=10)
        self.problemsTextbox.config(state = DISABLED)
        self.problemsTextbox.grid(row = 4, column = 2)
        
        label = Label(self, text = "Mission")
        label.grid(row = 5, column = 2)
        
        self.missionTextbox = Text(self, width=30, height=10)
        self.missionTextbox.config(state = DISABLED)
        self.missionTextbox.grid(row = 6, column = 2)
    
        button = Button(self, text = "Ajouter", command = self._onAddPressed)
        button.grid(row = 7, column = 0, rowspan = 3)

    def addDate(self, date):
        self.datesListbox.insert(END, date)

    def addProjectMemberName(self, name):
        self.membersListbox.insert(END, name)
        
    def getSelectedDate(self):
        return self.datesListbox.get(ACTIVE)
    
    def getSelectedProjectMemberName(self):
        return self.membersListbox.get(ACTIVE)
        
    def _setTextboxText(self, textbox, text):
        textbox.config(state = NORMAL)
        textbox.delete(1.0, END)
        textbox.insert(END, text)
        textbox.config(state = DISABLED)
        
    def setAccomplished(self, text):
        self._setTextboxText(self.accomplishedTextbox, text)
        
    def setProblems(self, text):
        self._setTextboxText(self.problemsTextbox, text)
        
    def setMission(self, text):
        self._setTextboxText(self.missionTextbox, text)
        
    def _showSelectedScrum(self, dummy = None):
        self.listener.onShowSelectedScrum()

    def _onAddPressed(self):
        self.listener.onAddScrum()
